﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;

namespace AnyOffice.general.email
{
    public partial class index : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.AppendHeader("Expires", DateTime.Now.AddDays(-1.0).ToString("r"));
            Response.AppendHeader("Pragma", "no-cache");
            Response.AppendHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
            if (!this.Page.IsPostBack)
            {
                int inboxNums = 0;
                int inboxNewNums = 0;
                int outboxNums = 0;
                int num4 = 0;
                int num5 = 0;
                new EmailDao().Statistic(base.Conn, base.User.Identity.Name, ref inboxNums, ref inboxNewNums, ref outboxNums);
                this.litInboxNums.Text = inboxNums.ToString();
                this.litInboxNewNums.Text = inboxNewNums.ToString();
                this.litOutboxNums.Text = outboxNums.ToString();
                if (inboxNewNums > 0)
                {
                    this.imgNew.Visible = true;
                }
                num4 = inboxNums + outboxNums;
                num5 = inboxNewNums;
                DataTable table = new EmailBoxDao().Statistic(base.Conn, base.User.Identity.Name);
                if (table.Rows.Count > 0)
                {
                    this.rptBox.DataSource = table;
                    this.rptBox.DataBind();
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        num4 += Convert.ToInt32(table.Rows[i]["Nums"].ToString());
                        num5 += Convert.ToInt32(table.Rows[i]["NewNums"].ToString());
                    }
                }
                this.litTotalNums.Text = num4.ToString();
                this.litNewNums.Text = num5.ToString();
                long num7 = new EmailBoxDao().InboxSize(base.Conn, base.User.Identity.Name);
                UserCache cache = new UserCache();
                if (cache.EmailCapacity != 0)
                {
                    long size = ((cache.EmailCapacity * 1024) * 1024) - num7;
                    string str = (Convert.ToSingle(num7) / ((float)((cache.EmailCapacity * 1024) * 1024))).ToString("p");
                    string str2 = Convert.ToString((long)((num7 * 100L) / ((long)((cache.EmailCapacity * 1024) * 1024))));
                    this.ViewState["Percent"] = str2;
                    this.litWholeStatic.Text = "容量" + cache.EmailCapacity.ToString() + "M：已用" + StringHelper.FormatSize(num7) + "(" + str + ")，剩余" + StringHelper.FormatSize(size);
                }
                else
                {
                    this.ViewState["Percent"] = 1;
                    this.litWholeStatic.Text = "容量不限制：已用" + StringHelper.FormatSize(num7);
                }
            }
        } 

    }
}
